import request from '../utils/index'

// -------------首页接口-----------------
// 获取首页数据
export const reqGetIndexList = ()=> request({
  url:`/xhr/index.json?__timestamp=${Date.now()}`,
})

// 获取分页展示数据
export const reqGetPageGoodsList = (size)=>request({
    url:'/xhr/index/items.json?csrf_token=5542322650b550d05554ba2c69c775d4',
    method:'POST',
    data:{
      itemIdstr:'',
      size
    }
})

// 获取某个频道的相关信息
export const reqGetChannelInfo = (categoryId)=>request({
  url:`/item/list.json?__timestamp=${Date.now()}&categoryId=${categoryId}`
})


// ----- 值得买页面的接口 -----

// 请求分类轮播数据的接口函数
export function reqNavList(){
  return request({
    url:'/topic/v1/know/navWap.json'
  })
}

// 请求话题瀑布流的接口函数
export function reqTopicList(page,size){
  return request({
    url:`/topic/v1/find/recAuto.json?page=${page}&size=${size}`
  })
}

// ------------分类与搜索的接口------------
// 获取上方搜索框的接口函数
export function reqSearch(){
  return request({
    url:'/xhr/search/init.json',
  })
}

// 获取分类页的接口函数
export function reqCategory(categoryId){
  return request({
    url:`/item/cateList.json?__timestamp=1630131286110&categoryId=${categoryId}`
  })
}

// 获取实时搜索关键字的接口函数
export function reqAutoComplete(str){
  console.log(str)
  return request({
    method:'POST',
    url:`/xhr/search/searchAutoComplete.json`,
    header:{
      'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', 
    },
    data:{
      'keywordPrefix':str
    }
  })
}

// 获取搜索热门词汇
export function reqSearchTags(){
  return request({
    url:'/xhr/search/init.json'
  })
}

// 登录接口
export function reqLogin({password,phone}){
  wx.showLoading({
    title:'正在加载中'
  })
  return new Promise((resolve,reject)=>{
    wx.request({
      method:'POST',
      data:{password,phone},
      success(res){
        resolve(res.data)
      },
      fail(error){
        reject(error)
      },
      complete(){
        wx.hideLoading()
      },
    })
  })
}

// 获取某个分类下的商品列表
export function reqGoodsList({categoryType,subCategoryId,categoryId}){
  return request({
    url:`/item/list.json?__timestamp=1630133942864&categoryType=${categoryType}&subCategoryId=${subCategoryId}&categoryId=${categoryId}`
  })
}

// 用关键字搜索
export function reqSearchResultByKeyword({keyword,categoryId,upperPrice,floorPrice,descSorted}){
  return request({
    url:`/xhr/search/search.json?__timestamp=${Date.now()}&needPopWindow=true&searchWordSource=7&stillSearch=false&_stat_search=autoComplete&itemId=0&size=40&upperPrice=${upperPrice}&floorPrice=${floorPrice}&matchType=0&categoryId=${categoryId}&descSorted=${descSorted}&sortType=0&keyword=${keyword}`
  })
}
// 商品详情
export function reqGoodsDetail(id){
  return request({
    url:`/item/detail.json?csrf_token=e30fb89ab36d46bbf91f9b5cadd587a8&__timestamp=1693896592024&id=${id}`
  })
}